# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=maturin
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=0.12.6
pkgrel=1
pkgdesc='Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages (mingw-w64)'
url='https://github.com/pyo3/maturin'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-toml)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-rust)
source=("${_realname}-${pkgver}.tar.gz::https://github.com/pyo3/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('8642e6a64bd088930e666e930102db57b13bc652cc3498f5c2ddebd6359d059a')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root=${pkgdir} --optimize=1 --skip-build

  install -Dm644 license-mit ${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE
}
